修复:支持带 slug 的帖子 URL 解析#5
Open
joy717 wants to merge 1 commit into
Open
Conversation
The regex only matched the `/t/topic/{id}` form, so standard Discourse
share links that carry a slug (`/t/{slug}/{id}`) failed with
"无法从URL中解析出主题ID".
Broaden the pattern to `/t/(?:[^/]+/)?(\d+)(?:/\d+)?` so it accepts both
the slug form and the existing `/t/topic/{id}` form. Strictly more
permissive — no regression on the current case.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
@wozulong hi, could you review this pr? thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
ForumTopicInfo.from_url的正则只匹配/t/topic/{id}形式:Discourse 标准的分享链接会带 slug,形如
/t/{slug}/{id}(例如 ASCII 标题的帖子)。这类 URL 直接粘进来会解析失败,抛出无法从URL中解析出主题ID。复现:
修改
把正则放宽为:
slug 段变为可选,同时兼容两种形式,严格更宽松,不影响原有
/t/topic/{id}的解析。说明
边界情况:无 slug 的
/t/{id}/{post}会把 post 号误当成 id —— 但 Discourse 的规范 URL 一般都带 slug,实际不会出现。🤖 Generated with Claude Code